package TEST;

import java.util.ArrayList;
import java.util.Scanner;

public class Test1 {
    public static void main(String[] args) {
        ArrayList <Integer> list = new ArrayList<>();
        Scanner sc = new Scanner(System.in);

        while (true){
            System.out.println("请输入一个整数：");
            String i  = sc.nextLine();
            int num = Integer.parseInt(i);
            if(num > 100|| num< 1){
                System.out.println("输入错误，请重新输入：");
                continue;
            }
            list.add(num);
            int sum = getsum(list);
            if (sum >200){
                System.out.println("总和大于200，程序结束");
                break;
            }
        }
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));
            System.out.println(getsum(list));
        }
    }

    private static int getsum(ArrayList<Integer> list) {
        int sum = 0;
        for (int i = 0; i < list.size(); i++) {
            sum += list.get(i);
        }
        return sum;
    }
}

